//
//  LSRThemeCell.m
//  BaiSiProject
//
//  Created by lshenrong on 16/7/12.
//  Copyright © 2016年 lshenrong. All rights reserved.
//

#import "LSRThemeCell.h"
#import "LSRCellTopView.h"
#import "LSRThemeViewModel.h"
#import "LSRThemePictureView.h"
#import "LSRThemeItem.h"
#import "LSRThemeVoiceView.h"
#import "LSRThemeVideoView.h"
#import "LSRHotCommentView.h"
#import "LSRCommentItem.h"
#import "LSRThemeBottomView.h"


@interface  LSRThemeCell()

@property(weak,nonatomic) LSRCellTopView *cellTopView;
@property(weak,nonatomic) LSRThemePictureView *themePictureView;
@property(weak,nonatomic) LSRThemeVoiceView  *themeVoiceView;
@property(weak,nonatomic) LSRThemeVideoView  *themeVideoView;
@property(weak,nonatomic) LSRHotCommentView *commentView;
@property(weak,nonatomic) LSRThemeBottomView *bottomView;
@end

@implementation LSRThemeCell
-(void)setFrame:(CGRect)frame
{
    frame.origin.y+=10;
    frame.size.height-=10;
    [super setFrame:frame];

}

//把cell的类型改成自定义cell的类型，确保会调用这个方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //顶部View
        LSRCellTopView *cellTopView=[LSRCellTopView cellTopView];
        self.cellTopView=cellTopView;
        [self.contentView addSubview:cellTopView];
        //中间图片View
       LSRThemePictureView *themePictureView=[LSRThemePictureView cellThemePicture];
        self.themePictureView=themePictureView;
        
        [self.contentView addSubview:themePictureView];
        //中间声音View
        LSRThemeVoiceView *themeVoiceView=[LSRThemeVoiceView themeVoiceView];
        self.themeVoiceView=themeVoiceView;
       [self.contentView addSubview:themeVoiceView];
          //中间视频View
        LSRThemeVideoView *themeVideoView=[LSRThemeVideoView themeVideoView];
        self.themeVideoView=themeVideoView;
        [self.contentView addSubview:themeVideoView];

        
        //底部热评
        LSRHotCommentView *commentView=[LSRHotCommentView hotCommentView];
        
        self.commentView=commentView;
        [self.contentView addSubview:commentView];
        
        //底部工具条
        LSRThemeBottomView *bottomView=[LSRThemeBottomView bottomView ];
        self.bottomView=bottomView;
        [self.contentView addSubview:bottomView];
        

        
    }

   //注意return的对象
    return self;


}


-(void)setVm:(LSRThemeViewModel *)vm
{
    _vm=vm;
    /*设置顶部View的内容*/
    self.cellTopView.item=vm.themeItem;//调用点语法。把视图模型的数据传给模型
    //设置frame
    self.cellTopView.frame=vm.topViewFrame;
    /*设置中间View的内容*/
    
    if (vm.themeItem.type== LSRThemeTypePicture) {
        
           self.themeVideoView.hidden=YES;
           self.themeVoiceView.hidden=YES;//这里也要进行隐藏。这个bug居然没发现？？
           self.themePictureView.hidden=NO;//还原
           self.themePictureView.item=vm.themeItem;//调用点语法。把视图模型的数据传给模型
           self.themePictureView.frame=vm.themePictureFrame;
       
        
        
    }else if (vm.themeItem.type==LSRThemeTypeVoice)
        
    {   self.themeVideoView.hidden=YES;
        self.themePictureView.hidden=YES;
        self.themeVoiceView.hidden=NO;
        self.themeVoiceView.item=_vm.themeItem;//调用点语法。把视图模型的数据传给模型
        self.themeVoiceView.frame=_vm.themePictureFrame;
        
    
    }
    else if (vm.themeItem.type==LSRThemeTypeVideo)
    {
        self.themePictureView.hidden=YES;
        self.themeVoiceView.hidden=YES;
        self.themeVideoView.hidden=NO;
        self.themeVideoView.item=_vm.themeItem;//调用点语法。把视图模型的数据传给模型
        self.themeVideoView.frame=_vm.themePictureFrame;
    
    
    }

    //设置隐藏
    else
    {
        self.themePictureView.hidden=YES;
        self.themeVoiceView.hidden=YES;
        self.themeVideoView.hidden=YES;
    
    }
    if (vm.themeItem.commentItem) {
        
        self.commentView.hidden=NO;
        
        self.commentView.frame=vm.commentFrame;
        
        self.commentView.item=vm.themeItem;
        
    }
    else
    {
        self.commentView.hidden=YES;
    
    }
    
      /*设置底部bottomView的内容*/
    
    self.bottomView.frame=vm.bottomViewFram;
    self.bottomView.item=vm.themeItem;


}

@end
